package com.example.administrator.capital.home.invite;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.capital.R;
import com.example.administrator.capital.adapter.callback.OnPopWinDisMisBack;
import com.example.administrator.capital.base.BaseBackFragment;
import com.example.administrator.capital.utils.DisPlayUtils;
import com.example.administrator.capital.utils.ToastUtil;
import com.example.administrator.capital.widget.CustomPopupWindow;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 * 邀请界面
 */
public class InviteFragment extends BaseBackFragment {
    @BindView(R.id.invite)
    TextView mInvite;
    Unbinder unbinder;
    @BindView(R.id.relative)
    RelativeLayout mRelative;
    @BindView(R.id.web_view)
    WebView webView;
    private CustomPopupWindow mCustomPopupWindow;
    private TextView mBack;

    public InviteFragment() {
        // Required empty public constructor
    }

    public static InviteFragment newInstance() {
        Bundle args = new Bundle();
        InviteFragment fragment = new InviteFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_invite, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initView(View view) {
        super.initView(view);
        mBack = view.findViewById(R.id.app_title_back);
    }

    @Override
    protected void setListener() {
        super.setListener();
        mInvite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showSharePop();
            }
        });
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                _mActivity.onBackPressed();
            }
        });
    }

    @Override
    protected void setData() {
        super.setData();

        webView.loadUrl("file:///android_asset/yaoqing.html");
    }

    /**
     * 分享弹窗
     */
    private void showSharePop() {
        mCustomPopupWindow = new CustomPopupWindow(getContext(), R.layout.share_item,
                DisPlayUtils.getWidthPx(), DisPlayUtils.getHeightPx(), new OnPopWinDisMisBack() {
            @Override
            public void onPopWindowDismiss() {

            }
        }) {
            @Override
            public void setData(View view) {
                ImageView back_img = view.findViewById(R.id.back_img);
                ImageView action_list_bgView = view.findViewById(R.id.action_list_bgView);
                LinearLayout friend = view.findViewById(R.id.friend);
                LinearLayout wechat = view.findViewById(R.id.wechat);
                LinearLayout sina = view.findViewById(R.id.sina);
                LinearLayout qq = view.findViewById(R.id.qq);
                LinearLayout qzone = view.findViewById(R.id.qzone);
                DismissListener(back_img, action_list_bgView, friend, wechat, sina, qq, qzone);
            }
        };
        mCustomPopupWindow.showAsDownWindow(mRelative);
    }

    private void DismissListener(ImageView back_img, ImageView action_list_bgView, LinearLayout friend, LinearLayout wechat,
                                 LinearLayout sina, LinearLayout qq, LinearLayout qzone) {
        back_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCustomPopupWindow.dismissWindow();
            }
        });
        action_list_bgView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCustomPopupWindow.dismissWindow();
            }
        });
        friend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtil.showShort("分享到朋友圈");
                mCustomPopupWindow.dismissWindow();
            }
        });
        wechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtil.showShort("分享到微信");
                mCustomPopupWindow.dismissWindow();
            }
        });
        sina.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtil.showShort("分享到新浪");
                mCustomPopupWindow.dismissWindow();
            }
        });
        qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtil.showShort("分享到QQ");
                mCustomPopupWindow.dismissWindow();
            }
        });
        qzone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToastUtil.showShort("分享到QQ空间");
                mCustomPopupWindow.dismissWindow();
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
